using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UIDesigner
{
  class CppCode
  {
    public static string Utility()
    {
      return @"// Utility.h
#pragma once
#include <Windows.h>

HFONT GetFont(char *name, UINT size, bool is_bold, bool is_italic, bool is_underline, bool is_strike_out);
void FreeFont();


// Utility.cpp
#include <Windows.h>
#include <string.h>

namespace {

const int kMaxFontNumber = 256;

struct Font
{
 UINT size;
  bool is_bold;
  bool is_italic;
  bool is_underline;
  bool is_strike_out;
  char name[256];
  HFONT hFont;
};

Font g_font[kMaxFontNumber];
int g_font_number = 0;

}  //  namespace

HFONT GetFont(char *name, UINT size, bool is_bold, bool is_italic, bool is_underline, bool is_strike_out)
{
  if (!name) name = ""UI MS UI Gothic"";
  if (size == 0) size = 9;

  int i;
  for (i = 0; i < g_font_number; i++)
  {
    if (strcmp(name, g_font[i].name) == 0) {
      if (size == g_font[i].size) {
        if (is_bold == g_font[i].is_bold) {
          if (is_italic == g_font[i].is_italic) {
            if (is_underline == g_font[i].is_underline) {
              if (is_strike_out == g_font[i].is_strike_out) {
                return g_font[i].hFont;
              }
            }
          }
        }
      }
    }
  }
  if (g_font_number >= kMaxFontNumber) return NULL;
  HDC hDC = CreateCompatibleDC(NULL);
  HFONT hFont = CreateFontA(-MulDiv(size, GetDeviceCaps(hDC, LOGPIXELSY), 72),
    0, 0, 0, (is_bold == false ? 500 : FW_BOLD),
    is_italic, is_underline, is_strike_out, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
    CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH, name);
  DeleteDC(hDC);
  if (hFont) {
    g_font[i].size = size;
    g_font[i].is_bold = is_bold;
    g_font[i].is_italic = is_italic;
    g_font[i].is_underline = is_underline;
    g_font[i].is_strike_out = is_strike_out;
    g_font[i].hFont = hFont;
    g_font_number++;
  }
  return hFont;
}

void FreeFont()
{
  for (int i = 0; i < g_font_number; i++)
  {
    DeleteObject((HGDIOBJ)g_font[i].hFont);
  }
  g_font_number = 0;
}";
    }
  }
}
